<?php
/**
 * 房源来源类，消耗房源补录表
 * Class HouseSource
 */

namespace app\crontab\model;

use think\Model;

class HouseSource extends Model {

    // 直接使用配置参数名
    protected $connection = [
        // 数据库类型
        'type'     => 'mysql',
        // 服务器地址
        'hostname' => '127.0.0.1',
        // 数据库名
        'database' => 'fzp_erp',
        // 数据库用户名
        'username' => 'root',
        // 数据库密码
        'password' => 'Fzpfpy@818919',
        // 数据库编码默认采用utf8
        'charset'  => 'utf8',
        // 数据库表前缀
        'prefix'   => 'erp_',
    ];

    protected $table = 'erp_house_auction';

    /**
     * 获取需要更新的房源数据
     * @return mixedhuo
     */
    public function getNewHouse() {
        $time = strtotime("-2 months", strtotime(date('Y-m-d')));
//        print_r($time);exit;
        $where['h.bulu_time|ha.soure_updatetime|ha.itime|ha.utime'] = ['>=', $time];
//        $where['h.is_update'] = ['=', 1];
//        $where['h.village_id'] = ['=', 0];
//        $where = "h.bulu_time > 0 and (h.bulu_time >= {$time} or ha.soure_updatetime >= {$time})";
//        $where['ha.house_id'] = ['=', 5];
        print_r($where);
        // 拍卖信息
        $field = 'ha.source_id,ha.source_type,ha.court_name,ha.start_time,ha.end_time,ha.institution,ha.contact_name,ha.contact_tel,ha.initial_price,ha.bond,ha.consult_price,ha.market_price,ha.pay_selloff,ha.discount,ha.type,ha.predict_price,ha.price_lower_offset,ha.final_price,ha.tail_money_date,ha.enroll_num,ha.access_num,ha.remind_num,ha.deal_time,ha.bid_count,ha.auction_status,ha.source_url';
        // 房源信息
        $field .= ',h.*';
        $field .= ',hv.name as hv_name,hv.lng as hv_lng,hv.lat as hv_lat,hv.business_name as hv_business_name,hv.related_school as hv_related_school,hv.greening_rate as hv_greening_rate';
        return $this->alias('ha')->field($field)->join('erp_house h', 'h.auction_id = ha.id', 'LEFT')->join('erp_house_village hv', 'hv.id = h.village_id', "LEFT")->where($where)->select();
    }
}